//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//
//||||||||||||||||||||||||||||||||Map Creator|||||||||||||||||||||||||||||||//
//|||||||||||||||||||||||Created by: Cameron Ylimaki |||||||||||||||||||||||//
//||||||||||||||||||||||||||Gr 12 Java Programming||||||||||||||||||||||||||//
//|||||||||||||||||||||||||||||Date: May 5,2005|||||||||||||||||||||||||||||//
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//
//||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||//

package MapCreator;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.image.*;
import java.io.*;
import java.util.*;

class MapCreator extends JFrame implements ActionListener {
	int screenWidth;//gets the desired width that the user defines
	int screenHeight;//gets the desired height that the user defines
	int xPos=-10;//sets the inital position for the mouse os that it does not paint the initaL PIXLE ON THE SDCREEN
	int yPos=-10;
	int checkCount;//gets the image for the approiate image needed whe loading them
	int itemCount=0;//used to determine weather or not a item is wanted in a certian spot
	int enemyCount=0;//used to determine weather or not a item is wanted in a certian spot
	int trapCount=0;//used to determine weather or not a enemy is wanted in a certian spot
	int arrayNumb=0;//used to determine weather or not a enemy is wanted in a certian spot
	int i=0;// tells the east panel how many rows it needs for the number of images in the image folder
 	int counter=0;//used to draw the map
	int xCell; //used to give the x cell in the array
 	int yCell;//used to give the y cell in the array
 	int w=100;
	int h=100;
	int health;
	int attackDamage;
	int magic;
	boolean accuracy;
	String[] imageFileNames;// thjihs holds the array of image names in the image folder
	String drive; //This is used to save the the sub string used to find  the loaction of a file when its full path is not given.   
	String width;//this is used to hold the string of the size of teh frame that so that i can later change it from a strinng to a int. 
	String height;
	JPanel mainPanel=new JPanel();//makes the main j ppane
	JPanel paintPanel=new JPanel();// makes the paint j panel that is ised to hol;d all the paint ing and array information
	JPanel eastPanel=new JPanel();// holds all the pictures from the the image folder
	JPanel southPanel=new JPanel();//holds the menu bar and properties bar
	JPanel southAddition=new JPanel();// ithis j panel ifs for the properties of the map spot s holds all the buttons for them
	Image groundPic =Toolkit.getDefaultToolkit().getImage("ground.gif");//loads the Image to the image variable
 	Image grassPic=Toolkit.getDefaultToolkit().getImage("grassSmall.gif");//loads the Image to the image variable
 	Image waterPic=Toolkit.getDefaultToolkit().getImage("water.gif");//loads the Image to the image variable
 	Image treePic=Toolkit.getDefaultToolkit().getImage("tree.gif");//loads the Image to the image variable
 	Image images[];// used top hold all the images in the images folder according to how many images are in the images folder
	final JFileChooser fileChooser;//makes the file chooser
	BufferedImage buffImage;// used to take the buffered image drawn and puts it into a image whing you see on the screen
	Graphics image;// this is the graphic thge the buffer writes to
	boolean observer=false;// used to set the modes opf the mapping program
	boolean property=false;// used to set the modes opf the mapping program
	boolean painter=true;// used to set the modes opf the mapping program
	File file;// used to hold the string of the file to save it to
	JLabel lblProperty=new JLabel("Array Position Properties");// this is the properties title
	JLabel lblTrap=new JLabel("Trap: ");//tells if the variable is true or false;
	JLabel lblItem=new JLabel("Item: ");//tells if the variable is true or false;
	JLabel lblEnemy=new JLabel("Enemy: ");//tells if the variable is true or false;
	JLabel lblPosition= new JLabel("Click a box to get it's Porperties");// Holds and displays the position of the array that is clicked on in the observer mode
	JRadioButton radButEnemy= new JRadioButton("Enemy");// these buttons are used to determine if  and what properties are to be added to the array point at the map spot
	JRadioButton radButItem= new JRadioButton("Item");
	JRadioButton radButTrap= new JRadioButton("Trap");
 	MapSpot[][] map;//makes the map array
 	JScrollPane paintScrollPane;
 	
 		
	public MapCreator() {
		super("Map Creator");
		ReSizeMap();///gets and initializes the size oif the map
     	LoadImages();//loads the images from the image folder into an array
     	AddImagesToPanel();//adds tehhimages to panle which has a scroll pane
     	counter=0;//sets this to 0 for re sizing matters
		SetGui();//puts all to button s of the frame
		DisablePropertyButtons();//disables property buttons
		
		fileChooser = new JFileChooser();//creates the file chooser so the user is able to use it
		addWindowListener(new WindowAdapter() {	public void windowClosing(WindowEvent e) {dispose();System.exit(0);}});	
	}
	 	
	public void actionPerformed(ActionEvent e){//this is what happens when a button is pushed it determines what happens
		String action = e.getActionCommand();//makes the action command which is a string and puts it into the variable action
		System.out.println("\n\nAction Preformed: "+e.getActionCommand());
	
		if(action=="Help Topics"){
			JOptionPane.showMessageDialog(null,"Help Needed","Map Creator - Help", JOptionPane.INFORMATION_MESSAGE);
		}
		
		if(action=="Save"){//if save is clicked 
			
			
			filefilter ff = new filefilter();//makes a new filefilter for m3u only
			fileChooser.addChoosableFileFilter(ff);//adds ff to file chooser
			int returnVal = fileChooser.showSaveDialog(null);// show the open dialog window
					
			if (returnVal == JFileChooser.APPROVE_OPTION) {
		        file = fileChooser.getSelectedFile();// gets the path of the selected file
				this.setTitle("Map Creator - "+(file));//this sets the title tho the name of the opened or saved file
	  			try
		  		{
			  		System.out.println("\n\nSaving File To: "+file);
			  		FileOutputStream fos = new FileOutputStream(file+".mlf");//sets the file location and file name to be saved
					ObjectOutputStream oos = new ObjectOutputStream(fos);//creastes the object out put stream
					oos.writeObject(map);//writes the map to the file
					oos.writeObject(width);//writes the width of the map to the file
					oos.writeObject(height);// writes the height of tehmap to the file
					oos.close();//closes the stream
		      	}
				catch(IOException ex){// cathces the errors and gives a msg box if one occurs
					JOptionPane.showMessageDialog(null,"There was an Error When Trying Save The File","Map Creator", JOptionPane.ERROR_MESSAGE);
					ex.printStackTrace(System.out);
				}
			}
		}
		
		if(action=="Load"){// thsi is what happens if the action string== Load
			fileChooser.resetChoosableFileFilters();// resets tjhe file chooser
			filefilter ff = new filefilter();//makes a new filefilter for m3u only
			fileChooser.addChoosableFileFilter(ff);//adds ff to file chooser
			int returnVal = fileChooser.showOpenDialog(null);// show the open dialog window
					
			if (returnVal == JFileChooser.APPROVE_OPTION) {
		        file = fileChooser.getSelectedFile();// gets the path of the selected file
		        drive= file.getPath().substring(0,3);// gets the sub string of the file
				this.setTitle("Map Creator - "+(file.getPath()));//gets the name of the loaded file and adds it to the title bar
			
				try{
	  				System.out.println("\n\nLoading From: "+file);
	  				FileInputStream fis = new FileInputStream(file);//sets the location to read the file from
					ObjectInputStream ois = new ObjectInputStream(fis);//makes a object input stream
					map=(MapSpot[][]) ois.readObject();//it reads teh file as a map spot  MapSpot[][]
					width=(String) ois.readObject();//reads the width of the map from the file
					height=(String) ois.readObject();//reads the height of the map from the file
					screenWidth=Integer.parseInt(width);//turns the width and height into integers so that theu can be used
					screenHeight=Integer.parseInt(height);
					repaint();
	   			}//CAtches the errors and tells you generally what is wrong
				catch(FileNotFoundException fileNotFoundException){ // if theres a file not found exception
					JOptionPane.showMessageDialog(this,"The Specified File Doesn't Exist","Map Creator",JOptionPane.ERROR_MESSAGE);
				} 
			
				catch(IOException ioException){ // if there's reading or writing error
					JOptionPane.showMessageDialog(this,"Cannont Read The File. ERROR","Map Creator",JOptionPane.ERROR_MESSAGE); 
				}
			
				catch(ClassNotFoundException classNotFoundException){ // if theres a class not found exception
					JOptionPane.showMessageDialog(this,"A Class Not Found Error Occured","Map Creator",JOptionPane.ERROR_MESSAGE); 
				}
			}	
		}
		
		if(action=="New"){
			ReSizeMap();//calls re size map
			paintScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);//turns on the certical scroller
			paintPanel.setPreferredSize(new Dimension(screenWidth, screenHeight));//sets the size of my paint panel
			repaint();	
     	}
 
		if (action=="Exit"){// The exit button found in file Menu
			System.out.println("\n\nExit Program");
			System.exit(0);
		}
		
		if(action=="Painter Mode"){// if painter mode is selected
			painter=true;
			observer=false;//turns off all the other modes
			property=false;
			System.out.println("/n/nPainter Mode: "+painter);
			System.out.println("Observer Mode: "+observer);
			System.out.println("Property Mode: "+property);
			DisablePropertyButtons();//disables in needed buttons
			this.setSize(w+150,h+117);
			repaint();			
     	}
     	
     	if(action=="Observer Mode"){//if observer mode is selected same as above
			observer=true;
			painter=false;
			property=false;
			System.out.println("/n/nObserver Mode: "+observer);
			System.out.println("Painter Mode: "+painter);
			System.out.println("Property Mode: "+property);
			DisablePropertyButtons();
			this.setSize(w+10,h+117);
			repaint();
     	}
     	
     	if(action=="Change Property Mode"){//if change property mode is selected same as above
 			property=true;
			painter=false;
			observer=false;
     		System.out.println("\n\nProperty Mode: "+property);
     		System.out.println("Painter Mode: "+painter);
     		System.out.println("Observer Mode: "+observer);
     		EnablePropertyButtons();
     		this.setSize(w+10,h+117);
     		repaint();
     	}
		
		if(action=="Trap Property"){// what happens when the trap button is pressed
			trapCount++;// every tieme the button is clicked it then advances the counter.  in mouse dragged ans clicked it determins what to do if a certian number is chosen
			radButTrap.setText("Trap (True)");//changes the title of the button to trye so that the user knows if it is selected or not.  
			if(trapCount>1){
				trapCount=0;//resets the counter if it is greater than 1
				radButTrap.setText("Trap (False)");//sets the button title to false so the user knosw when the function is disabled
			}
		}
		if(action=="Item Property"){// what happens when the item button is pressed
			itemCount++;// every tieme the button is clicked it then advances the counter.  in mouse dragged ans clicked it determins what to do if a certian number is chosen
			radButItem.setText("Item (True)");//changes the title of the button to trye so that the user knows if it is selected or not.
			if(itemCount>1){//resets the counter if it is greater than 1
				itemCount=0;
				radButItem.setText("Item (False)");//sets the button title to false so the user knosw when the function is disabled
			}
		}
		if(action=="Enemy Proprety"){// what happens when the enemy button is pressed
			enemyCount++;// every tieme the button is clicked it then advances the counter.  in mouse dragged ans clicked it determins what to do if a certian number is chosen
			radButEnemy.setText("Enemy (True)");//changes the title of the button to trye so that the user knows if it is selected or not.
			if(enemyCount>1){//resets the counter if it is greater than 1
				enemyCount=0;
				radButEnemy.setText("Enemy (False)");//sets the button title to false so the user knosw when the function is disabled
			}
		}
	}	
	
	public class paintPanel extends JPanel implements MouseMotionListener, MouseListener{// this is my panel that i created sotha t i can piant on it and not on the buttons and sliders	 
		
		public paintPanel(){// this the the paintPanel function that was created adds listenors to it
			addMouseMotionListener(this);	
			addMouseListener(this);	 
		}		
		
		public void paint(Graphics g){// this is my overided paint function
			buffImage = new BufferedImage(screenWidth, screenHeight, BufferedImage.TYPE_3BYTE_BGR );//makes a spot in memory to make a buffered image
			image = buffImage.getGraphics();// puts the buffered image into the variable image
			image.setColor(Color.WHITE);// makes the image bkg white
			image.fillRect(0,0,screenWidth,screenHeight);// sets size of image
		
	     		for (xCell =0; xCell< screenWidth; xCell++ ){//the loops are used to chech each cell of the array to paint it
	     			for (yCell =0; yCell< screenHeight; yCell++ ){
	      				MapSpot ms = map[xCell][yCell];
	       				int imageSpot = ms.arrayNum;// sets the array number when it is painted so that only a certian number is painted a certian color or oicture
	      				Image drawToImage= images[imageSpot];// makwes a image to be drawn to
	      				image.drawImage(drawToImage, xCell*32, yCell*32, Color.white, this);// darws to the image jst created.  
					}
				}
	 			g.drawImage(buffImage, 0,0,Color.white, this);// draws to the bufffered image that was created earlier
		}

		public void mouseDragged(MouseEvent e){//what happens hen the mouse is dragged on screen
		    xPos = e.getX();//gets the coordinates of the mouse	
		    yPos = e.getY();
			xCell = xPos /32;
 			yCell = yPos /32;
 			
	  		try{
	  			if(painter==true){	
	  				map[xCell][yCell].arrayNum=arrayNumb;// this actually sets the array number of the pic wanted pinted to the array and at the MapSpot[][] when the mouse is dragged across the screen
			    //	map[xCell][yCell].arrayNum = arrayNumb;
			    }
			}
			catch(Exception Ex){//catches teherroes that occur when the mouse goes out of the array
				JOptionPane.showMessageDialog(null,"You cannont draw off the screen","Map Creator", JOptionPane.ERROR_MESSAGE);
			}	
			repaint();// repaints the screen
		}
		
		
		public void mouseClicked(MouseEvent e){//needed for the mouse type motionlisteror and or mouselistener 
  			try{
	  			xPos = e.getX();//gets the coordinates of the mouse	
			    yPos = e.getY();
	  			int xCell = xPos /32;
	 			int yCell = yPos /32;
	 			
	 		try{
	  			if(painter==true){	
	  				map[xCell][yCell].arrayNum=arrayNumb;// this actually sets the array number of the pic wanted pinted to the array and at the MapSpot[][] when the mouse is clicked on the screen	
			    //	map[xCell][yCell].arrayNum = arrayNumb;
			    }
			}
			catch(Exception Ex){//catches teherroes that occur when the mouse goes out of the array
				JOptionPane.showMessageDialog(null,"You cannont draw off the screen","Map Creator", JOptionPane.ERROR_MESSAGE);
			}	
			repaint();// repaints the screen
	 			
	 		if (property==true){// if in change property mode is selected
	  			if(trapCount==1){
	  				radButTrap.setText("Trap (True)");//sets the buttons name to true so that the user knows when it is true and false
	  				map[xCell][yCell].trap=true;	//  trap is added to the specified mapspot
	  			}
	  			else if(trapCount==0){
	  				radButTrap.setText("Trap (False)");
	  				map[xCell][yCell].trap=false;//  trap is removed from the specified mapspot
	  			}
	  			
	  			if(enemyCount==1){
	  				radButEnemy.setText("Enemy (True)");//  enemy is added to the specified mapspot
	  				map[xCell][yCell].enemy=new Enemy(health,attackDamage,accuracy,magic);	
	  			}
	  			else if(enemyCount==0){
	  				radButEnemy.setText("Enemy (False)");//  enemy is removed from the specified mapspot
	  				map[xCell][yCell].enemy=map[xCell][yCell].enemy=new Enemy(0,0,false,0);
	  			}
	  			
	  			if(itemCount==1){
	  				radButItem.setText("Item (True)");//  item is added to the specified mapspot
	  				map[xCell][yCell].item= (int)(Math.random() * 9) + 1;;	
	  			}
	  			else if(itemCount==0){
	  				radButItem.setText("Item (False)");//  item is removed from the specified mapspot
	  				map[xCell][yCell].item=0;
	  			}
  			}
  			
  			if(observer==true){// if observer mode is set to be on.  It tells the user what properties each map spot has
	 			lblPosition.setText("Properities Of The Current Array Postiton: X: " + xCell + " ,Y: " + yCell);
	  			lblEnemy.setText("Enemy: "+map[xCell][yCell].enemy);
				lblTrap.setText("Trap: "+map[xCell][yCell].trap);
				lblItem.setText("Item #: "+map[xCell][yCell].item);
			}
			}
			catch(Exception Ex){
				JOptionPane.showMessageDialog(null,"You cannont draw off the screen","Map Creator", JOptionPane.ERROR_MESSAGE); 
			}	  
		   	repaint();// repaints the screen
		}
		public void mouseMoved(MouseEvent e){}//needed for the mouse type motionlisteror and or mouselistener 
		public void mouseEntered(MouseEvent e){}//needed for the mouse type motionlisteror and or mouselistener 
		public void mouseExited(MouseEvent e){}//needed for the mouse type motionlisteror and or mouselistener 
		public void mousePressed(MouseEvent e){}//needed for the mouse type motionlisteror and or mouselistener 
		public void mouseReleased(MouseEvent e){}//needed for the mouse type motionlisteror and or mouselistener 
	
	}
		public void InitializeVariables(){//this is used to initialize all of the map xsspots in the a\rray. 
		for (int x =0; x< screenWidth; x++ ){
	     	for (int y =0; y< screenHeight; y++ ){
	     		map[x][y]=new MapSpot(false,null,0,0);//sets all the values for each map spot to 0
	     	}
	     }
	     repaint();
	}
	public void SetGui(){// this is used to add all the buttons and set their properties
		radButTrap.addActionListener(this);
		radButTrap.setActionCommand("Trap Property");
		
		radButItem.addActionListener(this);
		radButItem.setActionCommand("Item Property");
		
		radButEnemy.addActionListener(this);
		radButEnemy.setActionCommand("Enemy Proprety");
		
	
		
		
		JMenuBar menuBar1;// This is the menu bar that i have to hols my menu items.
		
		JMenu itemFile;//This is the sub menu in the menu bar that hold the JMenuItems. 
		JMenu itemView;//This is the sub menu in the menu bar that hold the JMenuItems.
		JMenu itemHelp;//This is the sub menu in the menu bar that hold the JMenuItems.
		JMenuItem helpFile;//This is the buttion that is put under the JMenu Help.
		JMenuItem load;  //This is the buttion that is put under the JMenu File.
		JMenuItem paintMode;  //This is the buttion that is put under the JMenu File.
		JMenuItem obMode;  //This is the buttion that is put under the JMenu File.
		JMenuItem cpMode;  //This is the buttion that is put under the JMenu File.
		JMenuItem save;  //This is the buttion that is put under the JMenu File.
		JMenuItem exit;  //This is the buttion that is put under the JMenu File.
		JMenuItem newfile;  //This is the buttion that is put under the JMenu File
		
		paintMode= new JMenuItem("Painter Mode"); 
		paintMode.addActionListener(this);
		paintMode.setActionCommand("Painter Mode");
		
		obMode= new JMenuItem("Observer Mode");
		obMode.addActionListener(this);
		obMode.setActionCommand("Observer Mode");
		
		cpMode= new JMenuItem("Property Mode");
		cpMode.addActionListener(this);
		cpMode.setActionCommand("Change Property Mode");
		
		helpFile= new JMenuItem("Help Topics");//Sets the properities for the help Topics Button in the help menu
		helpFile.setActionCommand("Help Topics");
		helpFile.addActionListener(this);
		
		save= new JMenuItem("Save");
		save.addActionListener(this);
		save.setActionCommand("Save");
		
		load= new JMenuItem("Load");		
		load.addActionListener(this);
		load.setActionCommand("Load");
		
		exit= new JMenuItem("Exit");
		exit.addActionListener(this);
		exit.setActionCommand("Exit");
		
		newfile= new JMenuItem("New");		
		newfile.addActionListener(this);
		newfile.setActionCommand("New");
		
		itemFile= new JMenu("File");//Sets the properities for the JMenu file
		itemFile.add(newfile);
		itemFile.add(load);/// adds the approiate burttons the the file menu
		itemFile.add(save);
		itemFile.add(exit);
		
		itemView=new JMenu("View");
		itemView.add(paintMode);
		itemView.add(obMode);
		itemView.add(cpMode);
			
		itemHelp= new JMenu("Help");//Sets the properities for the help j Menu
		itemHelp.add(helpFile);//adds the approiate button the the help menu
		
		menuBar1 = new JMenuBar();//Sets the properities for the JMenuBar
		menuBar1.add(itemFile);// adds the approiate drop menus to it
		menuBar1.add(itemView);
		menuBar1.add(itemHelp);	
		
		eastPanel.setLayout(new GridLayout(i,1));
		JScrollPane scrollPane=new JScrollPane(eastPanel);
		
		southAddition.setLayout(new GridLayout(2,5));
		southAddition.add(lblEnemy);
		southAddition.add(lblTrap);
		southAddition.add(lblItem);
		southAddition.add(radButEnemy);
		southAddition.add(radButTrap);
		southAddition.add(radButItem);
		
		
		
		southPanel.setLayout(new BorderLayout());
		southPanel.add(lblPosition,BorderLayout.NORTH);
		southPanel.add(southAddition,BorderLayout.SOUTH);
		
		paintPanel=new paintPanel();
		paintPanel.setPreferredSize(new Dimension(screenWidth, screenHeight));//this is used to set the perfered size of the paint panel
		paintScrollPane=new JScrollPane(paintPanel);//makes a scroll pane and addds the paint panel to it 
		paintScrollPane.setPreferredSize(new Dimension(859, 610));// sets the perrfered size of the scroll pane needed dso that the scroll bars show up. 
		paintScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);//makes the vertical scroll bar always appear.
	
		JPanel north=new JPanel();
		north.setLayout(new BorderLayout());
		north.add(menuBar1, BorderLayout.NORTH);
		north.add(southPanel,BorderLayout.SOUTH);
		
		mainPanel.setLayout(new BorderLayout());//sets its border layout
		mainPanel.add(north,BorderLayout.NORTH);
		mainPanel.add(paintScrollPane, BorderLayout.CENTER);
		mainPanel.add(scrollPane, BorderLayout.EAST);
		
		this.getContentPane().add(mainPanel);//this adds the main j panel p to the frame using get content pane function
		this.setSize(w+165,h+117);
		this.setVisible(true);		
	}
	
	public void LoadImages(){//Loads the images from the image folder into variables
		File imagesDir=new File("./Images/");//makes a new file and makes it equal to th eimages folder
		imageFileNames=imagesDir.list();// puts a list of the images and puts them into the image names variab;e
		
		if(imageFileNames==null){//if  there are not nems in the names variable then a message comes up and the program exits
			System.out.println("There Is No Folder Called Image In The Program Direcory");
			System.exit(0);
		}
		if(imageFileNames.length <1){// basically the same as above
			System.out.println("There Are No Image Files In The Image Directory");
			System.exit(0);
		}
			
		images = new Image[(imageFileNames.length)];//makes enoughf new images for as many there are in the images folder
 		checkCount=0;
 		
 		while(checkCount<imageFileNames.length){// this adds each image the the approiate image[]. and continues untiil all of the images are in a image[]
  			images[checkCount] = Toolkit.getDefaultToolkit().getImage("./images/" + imageFileNames[checkCount] + "/");
  			checkCount ++;
 		}
	}
	
	public void AddImagesToPanel(){//adds all the images that it loaded to the east panel
		JRadioButton radBtn[]=new JRadioButton[imageFileNames.length];// maakes enoughf buttons for each image
		 for (i = 0; i<images.length; i++){//sets all the images onto a radio buton according to how mant images there are. 
  			radBtn[i]=new JRadioButton(imageFileNames[i],new ImageIcon(images[i]));
  			//im setting every button so that it passes to PAINTPANEL what the active image should be
  			final int paintNumb=i;
 			radBtn[i].addActionListener(new ActionListener(){
 				 public void actionPerformed(ActionEvent e){
   					arrayNumb=paintNumb;//when any of the image redio buttons is pushed it sets it's number for the array.  
   				}
  			});
  			//add buttons to panel!
  			eastPanel.add(radBtn[i]);//adds all the buttons to the panel. 
 		}
 	}
 	public void ReSizeMap(){//used for sizing to array and screen to the proper size
 		try{
 			
 		counter++;
 		width=JOptionPane.showInputDialog("Type The Width Of The Map", "800"); //this variable gets the width umber the user wishes to frame to be 
		height=JOptionPane.showInputDialog("Type The Height Of The Map", "610");// same a above except for height
		screenWidth=Integer.parseInt(width);//sets the string of what the user wanted for the with and height and sets it to an integer so it can be used to size the frame and array 
		screenHeight=Integer.parseInt(height);//sets the string of what the user wanted for the with and height and sets it to an integer so it can be used to size the frame and array
		
		if(screenWidth==0){//makes it so that the user cant crash the program. no 0
			screenWidth=300;
		}
		if(screenHeight==0){//makes it so that the user cant crash the program. no 0			
			screenHeight=100;
		}
		if (screenWidth<=859){
			w=screenWidth;
		}
		else if (screenWidth>859){//makes the frame no bigger than 859
			w=859;	
		}
		if (screenHeight<=610){//makes the screen no bigger than 610
			h=screenHeight;
		}
		else if (screenHeight>610){
			h=610;	
		}
		
		map= new MapSpot[screenWidth][screenHeight];//makes the array the approiate size
		InitializeVariables();//initalizes all the map spots in the array
		//if(counter>1){
			this.getContentPane().add(mainPanel);//this adds the main j panel p to the frame using get content pane function
			this.setSize(w+165,h+117);//sets the size of the screen
			this.setVisible(true);	//makes the fram visiable
		//}
		
		repaint();
		}
		catch(Exception ex){}
		System.out.println("\n\nScreen Width: "+w);
		System.out.println("Screen Height: "+h);
		System.out.println("Map Width= "+screenWidth);
		System.out.println("Map Height= "+screenHeight);
 	}
 			
	public void DisablePropertyButtons(){//used to disable propreity panel buttons when not in property change mode
		radButEnemy.setEnabled(false);
		radButTrap.setEnabled(false);
		radButItem.setEnabled(false);
	}
	
	public void EnablePropertyButtons(){//enables the buttons when in proprety change mode
		radButEnemy.setEnabled(true);
		radButTrap.setEnabled(true);
		radButItem.setEnabled(true);
	}
	
	public static void main(String args[]) {
		System.out.println("Starting Map Creator...");
		MapCreator mainFrame = new MapCreator();	//makes the frame and starts the program	
	}
}

class Enemy implements Serializable{
	int health;
	int attackDamage;
	boolean accuracy;
	//Image enemyImage;
	int magic;	
	
	public Enemy(int hp, int ad, boolean ac, int m){
		health=hp;
		attackDamage=ad;
		accuracy=ac;
		magic=m;
	}		
}
class MapSpot implements Serializable{// this is my map spot class
	boolean trap;//these are the variables that each mapspot has
	Enemy enemy;
	int item;
	int arrayNum;
	
	public MapSpot(boolean t, Enemy e, int i,int a){	
		trap = t;//sets the mapspot variables from the constructor
		enemy = e;
		item = i;
		arrayNum = a;
	}

}
	
	 